import "package:flutter/material.dart";

class AnimateMenuItem {
  IconData? iconData;
  String title;
  String? imageUrl;
  Color? color;
  AnimateMenuItem({
    this.iconData,
    required this.title,
    this.imageUrl,
    this.color,
  });
}

// ignore: must_be_immutable
class AnimateMenu extends StatelessWidget {
  List<AnimateMenuItem> list = [
    AnimateMenuItem(
      title: '全部内容',
      iconData: Icons.dashboard,
      color: const Color.fromARGB(255, 79, 198, 233),
    ),
    AnimateMenuItem(
      title: '番剧',
      iconData: Icons.live_tv_rounded,
      color: const Color.fromARGB(255, 254, 91, 122),
    ),
    AnimateMenuItem(
      title: '国创',
      iconData: Icons.apple,
      color: const Color.fromARGB(255, 254, 91, 118),
    ),
    AnimateMenuItem(
      title: '时间表',
      iconData: Icons.calendar_today_outlined,
      color: const Color.fromARGB(255, 33, 174, 227),
    ),
    AnimateMenuItem(
      title: '少儿',
      iconData: Icons.child_friendly_rounded,
      color: const Color.fromARGB(255, 255, 127, 36),
    ),
    AnimateMenuItem(
      title: '7月新番',
      imageUrl: "./images/tab_1.jpg",
    ),
  ];
  AnimateMenu({super.key});
  @override
  Widget build(BuildContext context) {
    return SliverToBoxAdapter(
      child: Container(
        padding: const EdgeInsets.only(top: 10, bottom: 8),
        height: 75,
        child: ListView.builder(
          scrollDirection: Axis.horizontal,
          itemCount: list.length,
          itemBuilder: (BuildContext context, int index) {
            AnimateMenuItem e = list[index];
            Widget i =
                const CircleAvatar(radius: 18, backgroundColor: Colors.blue);
            if (e.iconData != null) {
              i = CircleAvatar(
                radius: 18,
                backgroundColor: e.color,
                child: Icon(
                  e.iconData,
                  size: 18,
                ),
              );
            } else if (e.imageUrl != null) {
              i = CircleAvatar(
                radius: 18,
                backgroundColor: e.color,
                backgroundImage: AssetImage(e.imageUrl!),
              );
            }
            return Container(
              margin: EdgeInsets.only(
                  right: index != list.length ? 14 : 0,
                  left: index == 0 ? 14 : 0),
              padding: const EdgeInsets.only(left: 32, right: 32),
              child: Column(
                children: [
                  Padding(
                    padding: const EdgeInsets.only(bottom: 4),
                    child: i,
                  ),
                  Text(
                    e.title,
                    style: const TextStyle(fontSize: 12, color: Color.fromARGB(255, 72, 77, 81)),
                  )
                ],
              ),
            );
          },
        ),
      ),
    );
  }
}
